<template>
  <view class="content">
    <image class="logo" src="/static/logo.png" />
    <view class="text-area">
		<div class="">
			<wd-input v-model="value111" placeholder="请输入用户名" clear-trigger="focus" clearable @input="handleChange"/>
			<wd-input v-model="value1" placeholder="请输入密码" clearable show-password @input="handleChange1"/>
		</div>
		<wd-button @click="login_all">登录</wd-button>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import {login} from '@/utils/api.ts'
import {useUserStore} from '@/store/login_value'
import {storeToRefs} from 'pinia'
import { onShow } from '@dcloudio/uni-app';

onShow(()=>{
  login_all()
})

const userStore = useUserStore()
// const {user} = storeToRefs(userStore)

const value111 = ref<string>('')
function handleChange(event) {
	value111.value = event.value

}
const value1 = ref<string>('')
function handleChange1(event) {
	value1.value = event.value		
	// console.log(event.value	,111)
}
// 登录



async function login_all(){
	let data =await login({name:value111.value,password:value1.value})

	userStore.changeUser(data.data[0])
localStorage.setItem('user_id',data.data[0]._id)

	uni.switchTab({
		url:'/',
	})
	
	localStorage.setItem('user_id',JSON.stringify(data.data[0]._id))
	

}
</script>


<style >
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}
</style>
